package servlet;

import bean.Result;
import com.google.gson.Gson;
import dao.QueryUserdao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/QueryUser.s")
public class QueryUserServlet extends HttpServlet {
    QueryUserdao dao=new QueryUserdao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final HttpSession session = req.getSession();
        final Object user = session.getAttribute("user");
        Map<String ,Object> map=new HashMap<>();
        map=dao.queryuser((String) user);
        System.out.println(map);
        Result result;
        result=new Result(1,"查询成功",map);
        final String json = new Gson().toJson(result);
        resp.getWriter().append(json);
    }
}
